package com.itboye.ihomebank.presenter;

import com.itboye.ihomebank.base.BasePresenter;
import com.itboye.ihomebank.base.ICompleteListener;
import com.itboye.ihomebank.bean.HouseBean;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.interfaces.IRepairInterface;
import com.itboye.ihomebank.responsitory.RepairRepository;

import java.util.Observer;

/***
 * 维修
 * 
 * @author 递增给Responsitory
 * 
 */
public class RepairPersenter extends BasePresenter implements
		IRepairInterface<HouseBean> {

	// 申请维修
	public static final String shenQingWeiXiu_success = "_shenQingWeiXiu_success";
	public static final String shenQingWeiXiu_fail = "_shenQingWeiXiu_fail";
	
	// 查看维修信息
	public static final String weixiuXinxi_success = "_weixiuXinxi_success";
	public static final String weixiuXinxi_fail = "_weixiuXinxi_fail";
	
	// 查看维修状态
	public static final String weixiuZhuangTai_success = "_weixiuZhuangTai_success";
	public static final String weixiuZhuangTai_fail = "_weixiuZhuangTai_fail";
	
	// 查看维修状态
	public static final String yiDao_success = "_yiDao_success";
	public static final String yiDao_fail = "_yiDao_fail";
	
	// 维修结束
	public static final String theEnd_success = "_theEnd_success";
	public static final String theEnd_fail = "_theEnd_fail";
	
	// 维修结束并评价
	public static final String theEndAndPingJia_success = "_theEndAndPingJia_success";
	public static final String theEndAndPingJia_fail = "_theEndAndPingJia_fail";
	
	// 维修结束并评价
	public static final String biaoQian_success = "_biaoQian_success";
	public static final String biaoQian_fail = "_biaoQian_fail";
	//协商维修金额
	public static final String xiugaiMoney_success = "_xiugaiMoney_success";
	public static final String xiugaiMoney_fail = "_xiugaiMoney_fail";
	
	//协商维修金额
	public static final String endAppy_success = "_endAppy_success";
	public static final String endAppy_fail = "_endAppy_fail";
	
	//维修地址
	public static final String dizhi_success = "_dizhi_success";
	public static final String dizhi_fail = "_dizhi_fail";
	//终止合同
	public static final String zhongzhi_success = "_zhongzhi_success";
	public static final String zhongzhi_fail = "_zhongzhi_fail";
	//房东验证终止申请
	public static final String yanzheng_success = "_yanzheng_success";
	public static final String yanzheng_fail = "_yanzheng_fail";

	//p2p列表
	public static final String p2p_query_success = "_p2p_query_success";
	public static final String p2p_query_fail = "_p2p_query_fail";

	public RepairPersenter(Observer observer) {
		super(observer);
	}
	/**
	 * 申请维修
	 */
	@Override
	public void shenQingWeiXiu(String uid,String image, String uname, String umobile,
			String repairId,String repairStatus, String ill, String address, String community,
			String status, String id) {
		// TODO Auto-generated method stub
		IRepairInterface<HouseBean> repair = new RepairRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(shenQingWeiXiu_success);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(shenQingWeiXiu_fail);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);

					}
				});
		repair.shenQingWeiXiu(uid,image, uname, umobile, repairId,repairStatus, ill, address,
				community, status, id);

	}
	/**
	 * 查看维修信息(用来返回报修类型)
	 */
	@Override
	public void weiXiuXinXi(String status) {
		IRepairInterface<HouseBean> repair = new RepairRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(weixiuXinxi_success);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(weixiuXinxi_fail);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);

					}
				});
		repair.weiXiuXinXi(status);
		
	}
	/**
	 * 查看维修状态
	 */
	@Override
	public void chanKanWeiXiu(String uid, String status) {
		IRepairInterface<HouseBean> repair = new RepairRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(weixiuZhuangTai_success);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(weixiuZhuangTai_fail);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);

					}
				});
		repair.chanKanWeiXiu(uid,status);
		
	}
	/**
	 * 师傅已到
	 */
	@Override
	public void shiFuYiDao(String pid) {
		IRepairInterface<HouseBean> repair = new RepairRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(yiDao_success);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(yiDao_fail);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);

					}
				});
		repair.shiFuYiDao(pid);
		
	}
	/**
	 * 维修结束
	 */
	@Override
	public void xiuLiEnd(String pid,String uid) {
		IRepairInterface<HouseBean> repair = new RepairRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(theEnd_success);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(theEnd_fail);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);

					}
				});
		repair.xiuLiEnd(pid,uid);
	}
	/**
	 * 维修结束并评价
	 */
	@Override
	public void xiuLiEndAndPingJia(String pid, String evaluate, String tags) {
		IRepairInterface<HouseBean> repair = new RepairRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(theEndAndPingJia_success);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(theEndAndPingJia_fail);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);

					}
				});
		repair.xiuLiEndAndPingJia(pid, evaluate, tags);
		
	}
	/**
	 * 查看师傅评价标签
	 */
	@Override
	public void biaoQian() {
		IRepairInterface<HouseBean> repair = new RepairRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(biaoQian_success);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(biaoQian_fail);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);

					}
				});
		repair.biaoQian();
		
	}
	/**
	 *  协商维修金额
	 */
	@Override
	public void xiuGaiMoney(String pid, String uid, String newmoney,String code) {
		IRepairInterface<HouseBean> repair = new RepairRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(xiugaiMoney_success);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(xiugaiMoney_fail);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);

					}
				});
		repair.xiuGaiMoney(pid, uid, newmoney,code);
	}
	@Override
	public void endApply(String uid, String repairId) {
		// TODO Auto-generated method stub
		IRepairInterface<HouseBean> repair = new RepairRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(endAppy_success);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(endAppy_fail);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);

					}
				});
		repair.endApply(uid, repairId);
	}
	@Override
	public void getWeiXiuDiZhi(String uid) {
		IRepairInterface<HouseBean> repair = new RepairRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(dizhi_success);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(dizhi_fail);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);

					}
				});
		repair.getWeiXiuDiZhi(uid);
		
	}

	@Override
	public void ZhongZhiHeTong(String uid, String contract_no, String apply_reason) {
		IRepairInterface<HouseBean> repair = new RepairRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(zhongzhi_success);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(zhongzhi_fail);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);

					}
				});
		repair.ZhongZhiHeTong(uid,contract_no,apply_reason);
	}

	@Override
	public void getYanZhengHeTong(String uid, String contract_no, String pass, String refuse_reason) {
		IRepairInterface<HouseBean> repair = new RepairRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(yanzheng_success);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(yanzheng_fail);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);

					}
				});
		repair.getYanZhengHeTong(uid,contract_no,pass,refuse_reason);
	}

	/**
	 * p2p列表
	 * @param current_page
	 * @param per_page
	 * @param b_status
     * @param dt_type
     */
	@Override
	public void P2PQuery(String current_page, String per_page, String b_status, String dt_type) {
		IRepairInterface<HouseBean> repair = new RepairRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(p2p_query_success);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(p2p_query_fail);
						RepairPersenter.this.setChanged();
						RepairPersenter.this.notifyObservers(result);

					}
				});
		repair.P2PQuery(current_page,per_page,b_status,dt_type);
	}

}
